<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>123</div>
  <script>
    let arr = [1, 2, 3, 4, 5, 6]
    arr.forEach(item=>{
   console.log(item)
    })
    // 自己封装forEach方法
    function selfForeach(arr, cb) {
      for (let i = 0; i < arr.length; i++) {
        let res = cb(arr[i],i)
      }
      return arr
    }
    const arr2= selfForeach(arr, (item,index) => {
      console.log(item,index)
      return 
    })
    // console.log(arr2);
  </script>
</body>

</html>